package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LCIT0105 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public boolean oneEditAway(String a, String b) {
            int n = a.length(), m = b.length();
            if (Math.abs(n - m) > 1) return false;
            if (n > m) return oneEditAway(b, a);
            int i = 0, j = 0, cnt = 0;
            while (i < n && j < m && cnt <= 1) {
                char c1 = a.charAt(i), c2 = b.charAt(j);
                if (c1 == c2) {
                    i++;
                    j++;
                } else {
                    if (n == m) {
                        i++;
                        j++;
                        cnt++;
                    } else {
                        j++;
                        cnt++;
                    }
                }
            }
            return cnt <= 1;
        }
    }

    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LCIT0105 an = new LCIT0105();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
